<?php
	/**
	 *	KLF Framework
	 *
	 *	Written by Kristian Oye <kristianoye@gmail.com> on Oct 23, 2011
	 *	Copyright (C) 2010-2011
	 */
namespace KLF\System\Web
{
	use KLF\System\Cache\KFakeCache;

	use KLF\System\KObject;
	use KLF\System\Cache\ICache;
	use KLF\System\Cache\KMemcache;
	use KLF\System\Web\KHttpSession;
	use KLF\System\Errors\KException;
	use KLF\System\Collections\KList;
	use KLF\System\Web\KHttpResponse;
	
	/**
	 *  Class KHttpContextBase - Contains information about this particular
	 *  HTTP request and response.
	 *
	 *  @package KLF\System\Web
	 *  @access public
	 *  @author Kristian Oye <kristianoye@gmail.com>
	 *  @since 0.1
	 *  
	 *  @method KHttpContext NewInstance
	 *  
	 *  @property KList $Errors Errors that have occurred during execution of the request.
	 *  @property KHttpApplication $Application The application that is currently executing.
	 *  @property IHttpHandler $Handler
	 *  @property KHttpRequest $Request The current HTTP request.
	 *  @property KHttpResponse $Response The current HTTP response.
	 *  @property KHttpServerUtility $Server The HTTP server utility.
	 *  @property KHttpSession $Session The current HTTP session.
	 *  @property ICache $Cache The cache object.
	 */
	class KHttpContext extends KObject
	{
		/**
		 * Contains errors that have occurred during the execution of the request.
		 * 
		 * @var KList
		 */
		protected $_propAllErrors;
		
		/**
		 * The application running in the current context.
		 * 
		 * @var KHttpApplication $_propApplication
		 */
		protected $_propApplication;
		
		/**
		 * The application state.
		 * 
		 * @var KApplicationState $_propApplicationState
		 */
		protected $_propApplicationState;
		
		/**
		 * The context for the application that is currently running.
		 * 
		 * @var KHttpContext $_rpropCurrent
		 */
		protected static $_rpropCurrent;
		
		/**
		 * The cache object.
		 * 
		 * @var ICache $_propCache
		 */
		protected $_propCache;
		
		/**
		 * The handler that will process the request.
		 * 
		 * @var IHttpHandler $_propHandler
		 */
		protected $_propHandler;
		
		/**
		 * The current HTTP request object.
		 * 
		 * @var KHttpRequest $_propRequest
		 */
		protected $_propRequest;
		
		/**
		 * The current HTTP response object.
		 * 
		 * @var KHttpRequest $_propResponse
		 */
		protected $_propResponse;

		/**
		 * A server utility for assisting in the dispatching of the request.
		 * 
		 * @var KHttpServerUtility $_propServer
		 */
		protected $_propServer;
		
		/**
		 * The session tied to the current request.
		 * 
		 * @var KHttpSession $_propSession
		 */
		protected $_propSession;
		
		/**
		 * Contains information about the current user. 
		 * 
		 * @var unknown_type
		 */
		protected $_propUserProfile;
		
		/**
		 * Constructs a new KHttpContext object.
		 *
		 * @author Kristian Oye <kristianoye@gmail.com>
		 * @since 0.1
		*/
		public function __construct(KHttpApplication $app)
		{
			$this->_propAllErrors = array();
			$this->_propApplication = $app;
			$this->_propCache = $app->Cache;
			$this->_propRequest = KHttpRequest::GetCurrentRequest();
			$this->_propResponse = new KHttpResponse();
			$this->_propServer = KHttpServerUtility::Instance();
			$this->_propSession = new KHttpSession($app);
		}
		
		/**
		 * Returns the current context.
		 * 
		 * @return KHttpContext
		 */
		public static function GetCurrentContext()
		{
			return self::$_rpropCurrent;
		}
	}
}
